Skip to content

Multiplexed Google Analytics support GA4 with UA backward compatibility #1

Open
sohale wants to merge 8 commits intobovlb:masterfrom
sohale:google-analytics-v4-ua-suppport
Open

Multiplexed Google Analytics support GA4 with UA backward compatibility #1
sohale wants to merge 8 commits intobovlb:masterfrom
sohale:google-analytics-v4-ua-suppport

Conversation

@sohale
Copy link

@sohale sohale commented Jan 29, 2026

Dual Compatibility for Google Analytics Support: v4 (GA4) and UA

This PR provides a sustainable solution for issue #63 by enabling the theme to support both Google Analytics v4 (GA4) and Universal Analytics (UA) tracking IDs.

The user only sets the google_analytics_v4:. The legacy users can keep using google_analytics:. The user does not even need to be aware of the other version. It feels like auto-detection.

Key Features

  • Backward compatibility: Existing sites using only UA or only GA4 will continue to work without changes.
  • Dual compatibility: Supports both google_analytics_v4 (GA4) and google_analytics (UA) configuration variables in _config.yml.
  • Simple configuration: Users can set one variables in _config.yml as needed. Even if they use both, in theory is will make sense: they may want to use it to track the page by two Analytics IDs.
  • Extendible: In future, new versions will arrive. This pattern can accommodate other versions if we need to support it long-term.
  • Brand agnostic: Other companies, non-google, solutions can use the same pattern.

Usage

In your _config.yml:

google_analytics_v4: G-XXXXXXXXXX   # For GA4
google_analytics: UA-XXXXXXXX-X     # For Universal Analytics

Note:

  • To credit @bovlb's solution, I forked the PR by @bovlb in PR #134, so it will in the commit history and a joint merge commit.

tsusdere and others added 8 commits January 2, 2024 16:07
This should work with both old Universal Analytics (UA) and new Google Analytics v4 (GA4).

Resolves pages-themes#63
This solution can be extended if we wanted to long-term support other tracking ID versions or variants.

The user can just specify the property for their version/variant in _config.yml
@sohale sohale changed the title Multiple Google Analytics support GA4 with UA backward compatibility Multiplexed Google Analytics support GA4 with UA backward compatibility Jan 29, 2026
@sohale sohale marked this pull request as ready for review January 29, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants